<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 7/18/2018
 * Time: 1:40 PM
 */


$user_online="count.txt";
touch($user_online);
$timeout=60;
$user_arr=file_get_contents($user_online);
$user_arr=explode("#",rtrim($user_arr,'#'));
$temp=array();
foreach ($user_arr as $value){
    $user=explode(",",trim($value));
    if(($user[0]!=getenv('REMOTE_ADDR'))&&($user[1]>time())){
        array_push($temp,$user[0].",",$user[1]);

    }

}
array_push($temp,getenv('REMOTE_ADDR').",".(time()+($timeout)).'#');
$user_arr=implode("#",$temp);
$fp=fopen($user_online,"w");
flock($fp,LOCK_EX);
fputs($fp,$user_arr);

$coun=count($temp);
$dat = array(
   'count'=>$coun,

);
//echo json_encode($dat);

$total_data = array("n" =>"$coun");
echo $_GET["jsonp"].'('. json_encode($total_data) . ')';

